package com.ruoyi.recycle.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.recycle.domain.HousekeepingCommodity;
import com.ruoyi.recycle.service.IHousekeepingCommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 家政服务列Controller
 *
 * @author ruoyi
 * @date 2022-05-22
 */
@RestController
@RequestMapping("/housekeepingCommodity")
@Api(tags = "家政服务")
public class HousekeepingCommodityController extends BaseController {
    @Autowired
    private IHousekeepingCommodityService housekeepingCommodityService;

    /**
     * 查询家政服务列列表
     */
    @RequiresPermissions("recycle:housekeepingCommodity:list")
    @GetMapping("/list")
    @ApiOperation("查询家政服务列列表")
    public TableDataInfo list(HousekeepingCommodity housekeepingCommodity) {
        startPage();
        List<HousekeepingCommodity> list = housekeepingCommodityService.selectHousekeepingCommodityList(housekeepingCommodity);
        return getDataTable(list);
    }

    /**
     * 导出家政服务列列表
     */
    @RequiresPermissions("recycle:housekeepingCommodity:export")
    @Log(title = "家政服务列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出家政服务列列表")
    public void export(HttpServletResponse response, HousekeepingCommodity housekeepingCommodity) {
        List<HousekeepingCommodity> list = housekeepingCommodityService.selectHousekeepingCommodityList(housekeepingCommodity);
        ExcelUtil<HousekeepingCommodity> util = new ExcelUtil<HousekeepingCommodity>(HousekeepingCommodity.class);
        util.exportExcel(response, list, "家政服务列数据");
    }

    /**
     * 获取家政服务列详细信息
     */
    @RequiresPermissions("recycle:housekeepingCommodity:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取家政服务列详细信息")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(housekeepingCommodityService.selectHousekeepingCommodityById(id));
    }

    /**
     * 新增家政服务列
     */
    @RequiresPermissions("recycle:housekeepingCommodity:add")
    @Log(title = "家政服务列", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增家政服务列")
    public AjaxResult add(@RequestBody HousekeepingCommodity housekeepingCommodity) {
        return toAjax(housekeepingCommodityService.insertHousekeepingCommodity(housekeepingCommodity));
    }

    /**
     * 修改家政服务列
     */
    @RequiresPermissions("recycle:housekeepingCommodity:edit")
    @Log(title = "家政服务列", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改家政服务列")
    public AjaxResult edit(@RequestBody HousekeepingCommodity housekeepingCommodity) {
        return toAjax(housekeepingCommodityService.updateHousekeepingCommodity(housekeepingCommodity));
    }

    /**
     * 删除家政服务列
     */
    @RequiresPermissions("recycle:housekeepingCommodity:remove")
    @Log(title = "家政服务列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除家政服务列")
    @ApiImplicitParam(name = "ids", value = "id集合", dataType = "List")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(housekeepingCommodityService.deleteHousekeepingCommodityByIds(ids));
    }
}
